package com.example.cola.client.api;

import com.example.cola.client.api.dto.*;
import com.example.cola.client.facade.UserFacade;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 用户控制器
 * 
 * @author 资深开发专家
 * @version 1.0
 */
@RestController
@RequestMapping("/api/users")
public class UserController {
    
    private final UserFacade userFacade;
    
    public UserController(UserFacade userFacade) {
        this.userFacade = userFacade;
    }
    
    /**
     * 创建用户
     */
    @PostMapping
    public Response<UserDTO> createUser(@Valid @RequestBody UserCreateCmd cmd) {
        return userFacade.createUser(cmd);
    }
    
    /**
     * 更新用户信息
     */
    @PutMapping("/{userId}")
    public Response<UserDTO> updateUser(@PathVariable Long userId, 
                                       @Valid @RequestBody UserUpdateCmd cmd) {
        return userFacade.updateUser(userId, cmd);
    }
    
    /**
     * 用户登录
     */
    @PostMapping("/login")
    public Response<String> login(@Valid @RequestBody UserLoginCmd cmd) {
        return userFacade.login(cmd);
    }
    
    /**
     * 根据ID查询用户
     */
    @GetMapping("/{userId}")
    public Response<UserDTO> getUserById(@PathVariable Long userId) {
        return userFacade.getUserById(userId);
    }
    
    /**
     * 分页查询用户
     */
    @GetMapping
    public Response<PageResult<UserDTO>> queryUsers(UserQuery query) {
        return userFacade.queryUsers(query);
    }
    
    /**
     * 启用用户
     */
    @PutMapping("/{userId}/enable")
    public Response<Void> enableUser(@PathVariable Long userId) {
        return userFacade.enableUser(userId);
    }
    
    /**
     * 禁用用户
     */
    @PutMapping("/{userId}/disable")
    public Response<Void> disableUser(@PathVariable Long userId) {
        return userFacade.disableUser(userId);
    }
}
